<template>
  <div class="radio">
    <the-header></the-header>
    <van-sticky>
      <div class="tag-list">
        <div v-for="(item,index) in tagList" :key="index"
          class="tag-item"
          :class="{ active:index === currentIndex }"
          @click="itemClick(item,index)">
          <div class="tag-img"  
            :class="{ bckimg:index === currentIndex }"
            :style="{ backgroundImage: 'url(' + item.picWebUrl + ')' }"></div>
          <div class="tag-title">
            <span>{{ item.name }}</span>
          </div>
        </div>
      </div>
    </van-sticky>

    <div class="wrap" v-if="currentIndex === 0">
      <new-radio :title="newradioTitle" :data="newradioList"></new-radio>
      <rank-list :title="rankTitle" :data="rankList"></rank-list>
    </div>

    <div class="wrap" v-if="currentIndex === 1">
      <new-radio :title="newradioTitle" :data="newradioList"></new-radio>
      <rank-list :title="rankTitle" :data="rankList"></rank-list>
    </div>

    <div class="wrap" v-if="currentIndex === 2">
      <new-radio :title="newradioTitle" :data="newradioList"></new-radio>
      <rank-list :title="rankTitle" :data="rankList"></rank-list>
    </div>

    <div class="wrap" v-if="currentIndex === 3">
      <new-radio :title="newradioTitle" :data="newradioList"></new-radio>
      <rank-list :title="rankTitle" :data="rankList"></rank-list>
    </div>

    <div class="wrap" v-if="currentIndex === 4">
      <new-radio :title="newradioTitle" :data="newradioList"></new-radio>
      <rank-list :title="rankTitle" :data="rankList"></rank-list>
    </div>

    <div class="wrap" v-if="currentIndex === 5">
      <new-radio :title="newradioTitle" :data="newradioList"></new-radio>
      <rank-list :title="rankTitle" :data="rankList"></rank-list>
    </div>

    <div class="wrap" v-if="currentIndex === 6">
      <new-radio :title="newradioTitle" :data="newradioList"></new-radio>
      <rank-list :title="rankTitle" :data="rankList"></rank-list>
    </div>

    <div class="wrap" v-if="currentIndex === 7">
      <new-radio :title="newradioTitle" :data="newradioList"></new-radio>
      <rank-list :title="rankTitle" :data="rankList"></rank-list>
    </div>

    <div class="wrap" v-if="currentIndex === 8">
      <new-radio :title="newradioTitle" :data="newradioList"></new-radio>
      <rank-list :title="rankTitle" :data="rankList"></rank-list>
    </div>

    <div class="wrap" v-if="currentIndex === 9">
      <new-radio :title="newradioTitle" :data="newradioList"></new-radio>
      <rank-list :title="rankTitle" :data="rankList"></rank-list>
    </div>

    <div class="wrap" v-if="currentIndex === 10">
      <new-radio :title="newradioTitle" :data="newradioList"></new-radio>
      <rank-list :title="rankTitle" :data="rankList"></rank-list>
    </div>

    <div class="wrap" v-if="currentIndex === 11">
      <new-radio :title="newradioTitle" :data="newradioList"></new-radio>
      <rank-list :title="rankTitle" :data="rankList"></rank-list>
    </div>

    <div class="wrap" v-if="currentIndex === 12">
      <new-radio :title="newradioTitle" :data="newradioList"></new-radio>
      <rank-list :title="rankTitle" :data="rankList"></rank-list>
    </div>
    <div class="wrap" v-if="currentIndex === 13">
      <new-radio :title="newradioTitle" :data="newradioList"></new-radio>
      <rank-list :title="rankTitle" :data="rankList"></rank-list>
    </div>
    <div class="wrap" v-if="currentIndex === 14">
      <new-radio :title="newradioTitle" :data="newradioList"></new-radio>
      <rank-list :title="rankTitle" :data="rankList"></rank-list>
    </div>
    <div class="wrap" v-if="currentIndex === 15">
      <new-radio :title="newradioTitle" :data="newradioList"></new-radio>
      <rank-list :title="rankTitle" :data="rankList"></rank-list>
    </div>

    <div class="wrap" v-if="currentIndex === 16">
      <new-radio :title="newradioTitle" :data="newradioList"></new-radio>
      <rank-list :title="rankTitle" :data="rankList"></rank-list>
    </div>
    <div class="wrap" v-if="currentIndex === 17">
      <new-radio :title="newradioTitle" :data="newradioList"></new-radio>
      <rank-list :title="rankTitle" :data="rankList"></rank-list>
    </div>

    <div class="content" v-if="currentIndex === ''">
      <swiper :banners="banners"></swiper>
      <recommend-radio :title="recommendTitle" :data="recommendList"></recommend-radio>
      <top-list :title="topTitle" :data="topList"></top-list>

       <div class="music-recommend">
        <div class="radio-header">
          <span>音乐推荐·电台</span>
          <span class="more1" @click="currentIndex = 0">更多 ></span>
        </div>
        <music-recommend :data="cateList"></music-recommend>
      </div>

      <div class="music-recommend">
        <div class="radio-header">
          <span>生活·电台</span>
          <span class="more2" @click="more2Click">更多 ></span>
        </div>
        <music-recommend :data="lifeList"></music-recommend>
      </div>

      <div class="music-recommend">
        <div class="radio-header">
          <span>情感·电台</span>
          <span class="more3" @click="more3Click">更多 ></span>
        </div>
        <music-recommend :data="emotionList"></music-recommend>
      </div>

      <div class="music-recommend">
        <div class="radio-header">
          <span>创作翻唱·电台</span>
          <span class="more4" @click="more4Click">更多 ></span>
        </div>
        <music-recommend :data="createList"></music-recommend>
      </div>

      <div class="music-recommend knowledge">
        <div class="radio-header">
          <span>知识·电台</span>
          <span class="more4" @click="more5Click">更多 ></span>
        </div>
        <music-recommend :data="knowledgeList"></music-recommend>
      </div>
    </div>
  </div>
</template>

<script>
  import TheHeader from '../../components/TheHeader/TheHeader.vue'
  import Swiper from '../../components/Swiper/swiper.vue'
  import RecommendRadio from './cpns/recommend-radio.vue'
  import TopList from './cpns/toplist.vue'
  import MusicRecommend from './cpns/music-recommend.vue'
  import NewRadio from './cpns/new-radio.vue'
  import RankList from './cpns/rank-list.vue'

  import { getBanner, getDjCatelist, getRecommendDj, getradioToplist, getCategoryList, getHotRadio } from '../../api/radio'

  export default {
    components:{
      TheHeader,
      Swiper,
      RecommendRadio,
      TopList,
      MusicRecommend,
      NewRadio,
      RankList
    },

    data() {
      return {
        banners:[],
        tagList:[],
        currentIndex:'',
        recommendTitle:'推荐节目',
        recommendList:[],
        topTitle:'节目排行榜',
        topList:[],
        cateList:[],
        lifeList:[],
        emotionList:[],
        createList:[],
        knowledgeList:[],
        newradioTitle:'优秀新电台',
        newradioList:[],
        rankTitle:'电台排行榜',
        rankList:[],
      }
    },

    created(){
      this._getBanner();
      this._getDjCatelist();
      this._getRecommendDj();
      this._getradioToplist();

      // this._getCategoryList(11);
      getCategoryList(2).then((res) => {
        this.cateList = res.djRadios.slice(0,4);
      })
      getCategoryList(6).then((res) => {
        this.lifeList = res.djRadios.slice(0,4);
      })

      getCategoryList(3).then((res) => {
        this.emotionList = res.djRadios.slice(0,4);
      })

      getCategoryList(2001).then((res) => {
        this.createList = res.djRadios.slice(0,4);
      })

      getCategoryList(11).then((res) => {
        this.knowledgeList = res.djRadios.slice(0,4);
      })
    },

    methods:{
      _getBanner(){
        getBanner().then((res) => {
          // console.log(res);
          this.banners = res.data;
        })
      },

      _getDjCatelist(){
        getDjCatelist().then((res) => {
          // console.log(res);
          this.tagList = res.categories;
        })
      },

      _getRecommendDj(){
        getRecommendDj().then((res) => {
          // console.log(res);
          this.recommendList = res.programs;
        })
      },

      _getradioToplist(){
        getradioToplist().then((res) => {
          // console.log(res);
          res.toplist.forEach((item) => {
            this.topList.push(item.program);
          })
          // console.log(this.topList);
        })
      },

      _getCategoryList(type){
        getCategoryList(type).then((res) => {
          // console.log(res);
          this.newradioList = res.djRadios
          // this.cateList = res.djRadios.slice(0,4);
          // console.log(this.cateList);
        })
      },

      _getHotRadio(cateId){
        getHotRadio(cateId).then((res) => {
          // console.log(res);
          this.rankList = res.djRadios;
        })
      },

      itemClick(item,index){
        // console.log(item.id);
        this.currentIndex = index;
        this._getCategoryList(item.id);
        this._getHotRadio(item.id);
      },

      more1Click(){
        // this.currentIndex = 0;

        console.log('111');
      },

      more2Click(){
        console.log('222');
      },
      more3Click(){
        console.log('333');
      },
      more4Click(){
        console.log('444');
      },
      more5Click(){
        console.log('555');
      },
    },
  }
</script>

<style scoped>
/* .radio{
  height: 100%;
  overflow-y: auto;
} */

.tag-list{
  display: flex;
  /* flex-wrap: wrap; */
  padding-top: 65px;
  padding-left: 10px;
  margin-right: 10px;
  overflow-x: auto;
  background: #fafafa;
}

.tag-item{
  /* display: flex; */
  /* flex: 30%; */
  /* flex-direction: column; */
  /* align-items: center; */
  /* width: 50%; */
  padding-bottom: 5px;
  border: 2px solid #fafafa;
  border-radius: 5px;
}

.tag-img{
  width: 50px;
  height: 50px;
  /* background-position: 47px; */
}

.tag-title{
  text-align:center;
  font-size: 13px;
  width: 59px;
}

.radio-header{
  padding-left: 10px;
  padding-right: 10px;
  display: flex;
  justify-content: space-between;
  border-bottom: 1px solid #fc6464;
}

.knowledge{
  padding-bottom: 60px;
}

.bckimg{
  background-position: 50px;
}

.active{
  color: #fc6464;
  border: 2px solid #fc6464;
  border-radius: 5px;
}
</style>